<template>
   <view class="xmain">
   <headBar :title="appTitle"></headBar>
    <view class="qTab">
      <view class="uni-flex uni-row kemuTitleHead">
        <view class="flex-item">
          <view @click="selectTab(0,true)" :class="tabIndex == 0 ? 'kemuTitleHeadFocus':''">科目一</view>
        </view>
        <view class="flex-item">
          <view @click="selectTab(1,true)" :class="tabIndex == 1 ? 'kemuTitleHeadFocus':''">科目四</view>
        </view>
      </view>
    </view>
     <view style="height: 40rpx;"></view>
    <view class="qContent">
     <view class="qContentLine uni-flex uni-row">
       <view class="qContentLineFlex flex-item">
         <view class=" uni-flex uni-column">
           <view class="flex-item flex-item-V iconRow" @click="indexDirect('/pages/question/question?subject='+(tabIndex == 0?1:4)+'&model='+model)">
             <uni-icons type="calendar" size="50rpx" color="#3495fc"></uni-icons>
             <view class="iconTitle">随机练习</view>
           </view>
           <view class="flex-item flex-item-V iconRow" @click="indexDirect('/pages/collect/lst')">
             <uni-icons type="star-filled" size="50rpx" color="#3495fc"></uni-icons>
             <view class="iconTitle">收藏题目</view>
           </view>
         </view>
       </view>
       <view class="qContentLineFlex flex-item">
         <view class=" uni-flex uni-column">
           <view class="flex-item flex-item-V circleRow" @click="indexDirect('/pages/sort/sort')">
             <view class="textContent" style="background: #05c0a3;border:5px solid #53ddc8;">
               <view style="height:45rpx;"></view>
               <view>顺序练习</view>
               <view>{{alreadyNum}}/{{totalNum}}</view>
             </view>
           </view>
           <view class="flex-item flex-item-V circleRow" @click="indexDirect('/pages/examin/examin?subject='+subject)">
             <view class="textContent" style="background: #ff6c41;border:5px solid #ff9453;">
               <view style="height:45rpx;"></view>
               <view>模拟考试</view>
               <view>仿真冲刺</view>
             </view>
           </view>
         </view>
       </view>
       <view class="qContentLineFlex flex-item">
         <view class=" uni-flex uni-column">
           <view class="flex-item flex-item-V iconRow" @click="indexDirect('/pages/wrong/lst')">
             <uni-icons type="close" size="50rpx" color="#3495fc"></uni-icons>
             <view class="iconTitle">错题收集</view>
           </view>
           <view class="flex-item flex-item-V iconRow" @click="resetQt()">
             <uni-icons type="refreshempty" size="50rpx" color="#3495fc"></uni-icons>
             <view class="iconTitle">题目重置</view>
           </view>
         </view>
       </view>
     </view>
    </view>
     <view style="height: 80rpx;"></view>
     <view class="checkQt">
       <view class="uni-flex uni-rows" @click="indexDirect('/pages/sign/sign')">
         <view class="flex-item" style="width:150rpx;">
           <image :src="'../../static/app_image/'+carType+'.png'" style="width:80rpx;height:80rpx;"></image>
         </view>
         <view class="flex-item">
           当前题库:
         </view>
         <view class="flex-item" style="margin-left: 20rpx;">
           {{currentCar.alias}}
         </view>
         <view class="flex-item" style="margin-left: 80rpx;">
           选择题库<uni-icons type="plus-filled"  color="#FFFFFF"></uni-icons>
         </view>
       </view>
     </view>
     <bootNav  nav="examine"></bootNav>
	</view>

</template>

<script>
	export default {

		data() {
			return {
				fangji:[],
        current_page:'',
        share:{
          title:this.appName,
          path:'/pages/index/index',
          imageUrl:'',
          desc:'',
          content:''
        },
        tabIndex:0,
        carType:'xiaoche',
        cheTypeList:{
          xiaoche:{alias:"小车",remark:"C1/C2/C3",model:"c1"},
          huoche:{alias:"货车",remark:"A2/B2",model:"a2"},
          keche:{alias:"客车",remark:"A1/A3/B1",model:"a1"},
          motoche:{alias:"摩托车",remark:"D/E/F",model:"d"},
        },
        totalNumList: {
          'c1':1323,
          'a1':3101,
          'a2':3109,
          'd':400,
          '4':1236
        },
        currentCar:{alias:"", remark:""},
        totalNum:0,
        alreadyNum:1,
        cacheSortTotalIndexKey:'cacheSortTotalIndex',
        subject:1,
        model:'',
			}
		},
    onShareAppMessage() {
      return {
        title: this.title,
      }
    },
    onShareTimeline: function() {
      return {
        title: this.title,
      }
    },
		onLoad(e) {
       var t = this;
       var carType = t.carType;
       var cheTypeList = t.cheTypeList;
       var storgeCarType = t.xCacheGet('carType');
       if(storgeCarType){
         carType = storgeCarType;
         t.carType = carType;
       }else{
         t.xCacheSet('carType',carType);
       }
       var currentCar = cheTypeList[carType];
       t.currentCar = currentCar;
       var totalNumList = t.totalNumList;
       var totalNum = totalNumList[currentCar['model']];
       t.totalNum = totalNum;
       var tab = 0;
       if(e.tab){
         tab = e.tab;
         tab = tab == 1 ? 1: 0;
       }
       t.tabIndex = tab;
       t.selectTab(tab);
    },
		methods: {
      selectTab(tabIndex,isDump){
        var t = this;
        if(!isDump){
          t.tabIndex = tabIndex;
          var currentCar = t.currentCar;
          var totalNumList = t.totalNumList;
          var totalNum = totalNumList[currentCar['model']];
          t.totalNum = totalNum;
          t.model = currentCar['model'];
          var cacheSortTotalIndex = t.xCacheGet(t.cacheSortTotalIndexKey);
          var subject = tabIndex === 0 ? 1 :4;
          t.subject = subject;
          if(cacheSortTotalIndex && cacheSortTotalIndex[currentCar.model+'_'+subject]){
            t.alreadyNum = cacheSortTotalIndex[currentCar.model+'_'+subject];
          }else{
            t.alreadyNum = 1;
          }

        }else{
          t.indexDirect('/pages/index/index?tab='+tabIndex)
        }
      },
      // 重置随机题库
      resetQt(){
        var t = this;
        var cheTypeList = t.cheTypeList;
        for(var i = 1;i<=10;i++){
          for(var x in cheTypeList){
            var cheType = cheTypeList[x];
            var key1 = 'rand_'+cheType['model']+'_1'+'_'+i;
            var key2 = 'rand_'+cheType['model']+'_4'+'_'+i;
            uni.removeStorage({key:key1});
            uni.removeStorage({key:key2});
          }
        }
        uni.showToast({title: '已刷新题库', icon: 'success', duration: 2000})
      },

      indexDirect(targetPage){
        var t =this;
        t.x_redirect(targetPage);
      }
		}
	}
</script>

<style>
	@import "../index/index.css";
</style>
